using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using BUS;
using DAL;
using Utility;

public partial class Admin_khachhangsua : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            LoadData();
        }
    }
    private void LoadData()
    {
        try
        {
            int id = int.Parse(Request.QueryString["id"].ToString());
            tbkhachhangDTO kh = tbkhachhangBUS.GetByID(id);
            if (kh != null)
            {

                txt_Makh.Text = kh.Makh.ToString();
                txt_tenkh.Text = kh.Tenkh;
                txt_diachi.Text = kh.Diachi;
                txt_dienthoai.Text = kh.Dienthoai;
                txt_email.Text = kh.Email;
                txr_matkhau.Text = kh.Matkhau;



            }
        }
        catch
        {
            Response.Redirect("khachhanglist.aspx");
        }
    }
    protected void btn_Update_Click(object sender, EventArgs e)
    {
        try
        {
            tbkhachhangDTO kh = new tbkhachhangDTO();
            //pham.Masp = int.Parse(txt_MaSp.Text);
            kh.Makh = int.Parse(txt_Makh.Text);
            kh.Tenkh= txt_tenkh.Text;
            kh.Diachi = txt_diachi.Text;
            kh.Dienthoai = txt_dienthoai.Text;
            kh.Email = txt_email.Text;
            kh.Matkhau = txr_matkhau.Text;


            tbkhachhangBUS.Update(kh);
            Response.Redirect("khachhanglist.aspx");
            Label_thanhcong.Text = tbkhachhangBUS.error;
        }

        catch
        {
            Label_thanhcong.Text = tbkhachhangBUS.error;
            Response.Redirect("khachhanglist.aspx");
        }
    }
}
